package one.bugu.android.demon.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import one.bugu.android.demon.R;

public class DialogFirstIn extends Dialog {

    private Context mContext;
    private TextView rankingHint;
    private TextView dragNumHint;
    private TextView dragNum;
    private TextView receiveBtn;


    public DialogFirstIn(@NonNull Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public DialogFirstIn(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
        initView();
    }

    protected DialogFirstIn(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
        initView();
    }

    private void initView() {
        View view = View.inflate(mContext, R.layout.dialog_first_in, null);
        setContentView(view);
        rankingHint = view.findViewById(R.id.tv_ranking);
        dragNumHint = view.findViewById(R.id.tv_drag_title);
        dragNum = view.findViewById(R.id.tv_drag_num);
        receiveBtn = view.findViewById(R.id.tv_receive_btn);

        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager wm = this.getWindow().getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        lp.width = width - 100;
        dialogWindow.setAttributes(lp);

        receiveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    /**
     * 设置数据
     *
     * @param ranking   排序
     * @param dragTotal 可获取币数
     */
    @SuppressLint("SetTextI18n")
    public void setData(int ranking, int dragTotal) {
        rankingHint.setText("恭喜您成为第" + ranking + "位农场主，");
        dragNumHint.setText("您的农场中已生产" + dragTotal + "个BGT,赶快领取吧！");
        dragNum.setText("X" + dragTotal);
    }
}
